/*
 * @Author: herw
 * @Date: 2021-04-20 14:56:49
 * @Last Modified by: herw
 * @Last Modified time: 2021-04-20 15:15:59
 */
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.blurry"
          clearable
          placeholder="模糊搜索"
          style="width: 200px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission">
        <template slot="right">
          <el-button
            v-permission="['admin', 'topic:add']"
            :disabled="!selectIndex"
            class="filter-item"
            size="mini"
            type="primary"
            icon="el-icon-upload"
            @click="mock"
          >
            <router-link
              :to="'/mq/mq/topic/producer/' + selectIndex"
            >生产消息</router-link>
          </el-button>
        </template>
      </crudOperation>
    </div>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      highlight-current-row
      stripe
      style="width: 100%"
      @selection-change="handleCurrentChange"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="name" label="Topic Name" />
      <el-table-column prop="fileSize" label="File Size" />
      <el-table-column prop="cluster.name" label="Cluster" />
      <el-table-column prop="createTime" label="Create Date">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="checkPermission(['admin', 'topic:edit', 'topic:del'])"
        label="操作"
        width="150px"
        align="center"
      >
        <template slot-scope="scope">
          <udOperation :data="scope.row" :permission="permission" />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import crudTopic from '@/api/mq/kafka/topic'

const defaultForm = { }
export default {
  name: 'Topic',
  components: { pagination, crudOperation, rrOperation, udOperation },
  cruds() {
    return CRUD({ title: 'Topic', url: 'api/mq/topic', crudMethod: { ...crudTopic }})
  },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  data() {
    return {
      selectIndex: '',
      permission: {
        add: ['admin', 'topic:add'],
        edit: ['admin', 'topic:edit'],
        del: ['admin', 'topic:del']
      }
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: true,
      del: false,
      download: true
    }
  },
  methods: {
    mock() {

    },
    handleCurrentChange(selection) {
      this.crud.selections = selection
      if (selection.length === 1) {
        const row = selection[0]
        this.selectIndex = row.id
      } else {
        this.selectIndex = ''
      }
    }
  }
}
</script>
